using System;
using System.Collections.Generic;
using System.Text;
using Vj.MathLibrary;
using System.Drawing;

namespace Vj.ParticlesLibrary
{
    public class FountainEmitter : Emitter
    {
        private int particleCount = 500;

        public FountainEmitter(Vector position)
        {
            this.particleList = new List<Particle>(particleCount);
            this.position = position;

            for (int i = 0; i < particleCount; i++)
                this.particleList.Add(this.CreateParticle());
        }

        protected override Particle CreateParticle()
        {
            // all particles will be emitted from systems center
            // so use systems position

            double angle = 3.0;
            Vector velocity = new Vector(RandomGrabber.Next(-angle, angle), 
                                         RandomGrabber.Next(0.0, angle), 
                                         RandomGrabber.Next(-angle,angle));
            
            velocity.Normalize();

            return new Particle(position, velocity,
                                Color.Red,
                                10+RandomGrabber.Next(50));
        }

        public override bool Update()
        {
            Particle particle;

            for (int i = 0; i < particleList.Count; i++)
            {
                particle = particleList[i];

                if (particle.Kill)
                {
                    //particleList.RemoveAt(i);
                    //i--;
                }
            }

            //if (particleList.Count > particleCount)
                //for (int i = particleList.Count; i < particleCount; i++)
                    //particleList.Add(CreateParticle());

            return true;
        }
    }
}
